<?php

namespace app\admin\model;

use think\Model;


class YjyHouse extends Model
{

    

    //数据库
    protected $connection = 'database';
    // 表名
    protected $name = 'yjy_house';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'sign_text',
        'is_suggestswitch_text'
    ];
    

    
    public function getSignList()
    {
        return ['radom' => __('Sign radom'), 'index' => __('Sign index')];
    }

    public function getIsSuggestswitchList()
    {
        return ['0' => __('Is_suggestswitch 0'), '1' => __('Is_suggestswitch 1')];
    }


    public function getSignTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['sign']) ? $data['sign'] : '');
        $valueArr = explode(',', $value);
        $list = $this->getSignList();
        return implode(',', array_intersect_key($list, array_flip($valueArr)));
    }


    public function getIsSuggestswitchTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_suggestswitch']) ? $data['is_suggestswitch'] : '');
        $list = $this->getIsSuggestswitchList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setSignAttr($value)
    {
        return is_array($value) ? implode(',', $value) : $value;
    }


}
